package com.hgzy.meeting.service;

import com.hgzy.meeting.mapper.EmployeeMapper;
import com.hgzy.meeting.model.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    /**
     * 登陆校验
     * @param username
     * @param password
     * @return
     */
    public  Employee doLogin(String username, String password) {
        return employeeMapper.doLogin(username, password);
    }

    /**
     * 注册用户
     * @param employee
     * @return
     */
    public int doReg(Employee employee) {
        Employee old_user=employeeMapper.findByName(employee.getUsername());
        System.out.println(old_user);
        // 如果查询到 数据库表中没有这个用户 返回-1 说明这个用户不存在数据库中 可以允许注册
        if (old_user != null) {
            return -1;
        }
//      设置是否拥有管理员权限 默认没有
        employee.setRole(1);
        //      设置是否审批 默认为0 未审批
        employee.setStatus(0);
        System.out.println(employee);
        return employeeMapper.doReg(employee);
    }

    /**
     * 查询 状态为某个值的用户
     * @param status
     * @return
     */
    public List<Employee> getAllEmployees(Integer status) {
        return employeeMapper.getAllEmployees(status);
    }

    public int updateStatus(Integer employeeId, Integer status) {
        return employeeMapper.updateStatus(employeeId, status);
    }

    public List<Employee> findEmployees() {
        return employeeMapper.findEmployees();
    }

    public long getTotal(Employee employee) {
        return employeeMapper.getTotal(employee);
    }

    public List<Employee> getAllEmps(Employee employee, Integer page, Integer pageSize) {
        page=(page-1)*pageSize;
        return employeeMapper.getAllEmps(employee, page, pageSize);
    }
}
